extends simplelayout
doctype html
block content

    html(lang='zh-CN')
        head
            meta(charset='utf-8')
            link(rel='icon', href='https://static.jianshukeji.com/highcharts/images/favicon.ico')
            meta(name="viewport" content="width=device-width, initial-scale=1")






    script(src='/javascripts/highcharts.js')

    script(src='/javascripts/highcharts-more.js')
    script(src='/javascripts/xrange.js')
    script(src='/javascripts/exporting.js')
    script(src='/javascripts/series-label.js')







    link(rel='shortcut icon', href='http://static.tmimgcdn.com/img/favicon.ico')
    link(rel='icon', href='http://static.tmimgcdn.com/img/favicon.ico')
    link(rel='stylesheet', type='text/css', media='all', href='/stylesheets/bootstrap.min.css')




    link(rel='stylesheet', type='text/css', media='all', href='/stylesheets/bootstrap-glyphicons.css')
    link(rel='stylesheet', type='text/css', media='all', href='/stylesheets/styles.css')
    script(src='/javascripts/jquery-1.11.0.min.js')

    script(src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.min.js")
    link(href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis-timeline-graph2d.min.css" rel="stylesheet" type="text/css")
    link(rel='stylesheet', type='text/css', media='all', href='/stylesheets/vis_timeline.css')





    body

    div(style="width: 1000px; margin: 50px 200px;")
        //info
        ul(id="header")


    //vis timeline
    div(style="margin: 50px 200px;" id="chartdiv"  )

    //lab//sign//medication
    div(style='min-width: 300px;max-width: 1500px;margin: 1em auto;', id="labchart"  )
    div(style='min-width: 300px;max-width: 1500px;margin: 1em auto;' , id="timechart3")
    div(style='min-width: 300px;max-width: 1500px;margin: 1em auto;' , id="timechart4")
    div(style='min-width: 300px;max-width: 1500px;margin: 1em auto;' , id="timechart1" )
    div(style='min-width: 300px;max-width: 1500px;margin: 1em auto;' , id="timechart2")


    //div(style="width: 1000px; margin: 50px 200px;")
    //    ul(id="position")



    script(type='text/javascript').

        function redirect_sign(a) {
            window.open("/search/graph_sign?q=" + a);
        }
        function redirect_lab(a) {
            window.open("/search/graph_lab?q=" + a);
        }
        function redirect_event(a) {
            window.open("/search/graph_event?q=" + a);
        }


        function search_id() {
            var Term = !{JSON.stringify(term)};
            $.ajax({
                url: "/search/id/list",
                type: "POST",
                data: {term: Term},

                success: function (data) {

                    if (data == '') {
                        alert("No corresponding data!");
                    } else {
                        //alert("success");
                        {
                            var html = "<li><div>";
                            html += "<p><span style='color:#14334b;font-size:20px'><strong>Subject ID: </strong>" + data[0].SUBJECT_ID + "</span></p>";
                            html += "<p><span style='color:#14334b;font-size:15px'><strong>Gender: </strong>" + data[0].GENDER + "</span></p>";
                            html += "<p><span style='color:#14334b;font-size:15px'><strong>Date of Born: </strong>" + data[0].DOB + "</span></p>";
                            if (data[0].EXPIRE_FLAG == "1")
                                html += "<p><span style='color:#14334b;font-size:15px'><strong>Confirmed Dead In Hospital: </strong>"+data[0].DOD+"</span></p>";
                            else
                                html += "<p><span style='color:#14334b;font-size:15px'><strong><I>Not Confirmed Dead In Hospital</I></strong></span></p>";

                            // html += "<p><button onclick='redirect_event(" + data[0].subject_id + ")'>events</button></p>";
                            html += "</div></li>";

                        }
                        $("#header").append($(html));
                        search_graph_event();

                    }
                }
            })
        }

        function search_graph_event() {
            var Term = !{JSON.stringify(term)};
            $.ajax({
                url: "/search/id/event",
                type: "POST",
                data: {term: Term},

                success: function (data) {
                    if (data[0] == '') {
                        // alert("No or lack of relevant data!" + "\n" + "Click to close the message box.");
                    } else {

                        //alert("success");

                        //判断异步查询的结果，将admission,discharge,transfer设为data0；将surgery设为data1
                        if (typeof data[0][0].MONITOR_TIME == "undefined") {
                            var data0 = data[0]
                            var data1 = data[1]
                        } else {
                            data1 = data[0]
                            data0 = data[1]
                        }



                        var admitFlag = 0;
                        var diachargeFlag = 0;
                        var surgeryFlag = 0
                        var transferFlag = 0;
                        var dataset = [];
                        var transfer = [{
                            HADM_ID: data0[0].HADM_ID,
                            ICUSTAY_ID: data0[0].ICUSTAY_ID,
                            EVENTTYPE: 'transfer',
                            CURR_CAREUNIT: data0[0].LAST_CAREUNIT,
                            CURR_WARDID: data0[0].LAST_WARDID,
                            INTIME: data0[0].INTIME,
                            OUTTIME: data0[0].OUTTIME
                        }];
                        transfer.push({
                            HADM_ID: data0[0].HADM_ID,
                            ICUSTAY_ID: data0[0].ICUSTAY_ID,
                            EVENTTYPE: 'admit',
                            CURR_CAREUNIT: data0[0].ADMISSION_LOCATION,
                            CURR_WARDID: null,
                            INTIME: data0[0].ADMITTIME,
                            OUTTIME: null
                        });
                        transfer.push({
                            HADM_ID: data0[0].HADM_ID,
                            ICUSTAY_ID: data0[0].ICUSTAY_ID,
                            EVENTTYPE: 'discharge',
                            CURR_CAREUNIT: data0[0].DISCHARGE_LOCATION,
                            CURR_WARDID: null,
                            INTIME: null,
                            OUTTIME: data0[0].DISCHTIME
                        });
                        var admit = [];
                        var discharge = [];
                        var icu = [];
                        var icustay = [];


                        for (var s = 0; s < data0.length; s++) {
                            var arr1 = {
                                HADM_ID: data0[s].HADM_ID,
                                ICUSTAY_ID: data0[s].ICUSTAY_ID,
                                EVENTTYPE: 'transfer',
                                CURR_CAREUNIT: data0[s].LAST_CAREUNIT,
                                CURR_WARDID: data0[s].LAST_WARDID,
                                INTIME: data0[s].INTIME,
                                OUTTIME: data0[s].OUTTIME
                            }
                            var arr2 = {
                                HADM_ID: data0[s].HADM_ID,
                                ICUSTAY_ID: data0[s].ICUSTAY_ID,
                                EVENTTYPE: 'admit',
                                CURR_CAREUNIT: data0[s].ADMISSION_LOCATION,
                                CURR_WARDID: null,
                                INTIME: data0[s].ADMITTIME,
                                OUTTIME: null
                            }
                            var arr3 = {
                                HADM_ID: data0[s].HADM_ID,
                                ICUSTAY_ID: data0[s].ICUSTAY_ID,
                                EVENTTYPE: 'discharge',
                                CURR_CAREUNIT: data0[s].DISCHARGE_LOCATION,
                                CURR_WARDID: null,
                                INTIME: null,
                                OUTTIME: data0[s].DISCHTIME
                            }


                            for (var r = 0; r < transfer.length; r++) {
                                if (isObjEqual(arr1, transfer[r])) transferFlag = 1;
                                // if (jQuery.inArray(arr1,transfer)!==-1) transferFlag=1;
                            }

                            if (transferFlag == 0) transfer.push(arr1);
                            transferFlag = 0;

                            for (var r = 0; r < transfer.length; r++) { //排除icustayid不同，其他相同 --> 导致多余admit/discharge数据的情况
                                if (arr2.HADM_ID == transfer[r].HADM_ID && arr2.EVENTTYPE == transfer[r].EVENTTYPE && arr2.CURR_CAREUNIT == transfer[r].CURR_CAREUNIT && arr2.CURR_WARDID == transfer[r].CURR_WARDID && arr2.INTIME == transfer[r].INTIME && arr2.OUTTIME == transfer[r].OUTTIME) transferFlag = 1;
                            }
                            if (transferFlag == 0) transfer.push(arr2);
                            transferFlag = 0;

                            for (var r = 0; r < transfer.length; r++) {
                                if (arr3.HADM_ID == transfer[r].HADM_ID && arr3.EVENTTYPE == transfer[r].EVENTTYPE && arr3.CURR_CAREUNIT == transfer[r].CURR_CAREUNIT && arr3.CURR_WARDID == transfer[r].CURR_WARDID && arr3.INTIME == transfer[r].INTIME && arr3.OUTTIME == transfer[r].OUTTIME) transferFlag = 1;
                            }
                            if (transferFlag == 0) transfer.push(arr3);
                            transferFlag = 0;
                        }

                        //有surgery记录
                        if (data1 != '') {
                            var surgery = [{
                                HADM_ID: data1[0].HADM_ID,
                                MONITOR_TIME: data1[0].MONITOR_TIME,
                                OPER_ID: data1[0].OPER_ID
                            }];

                            for (var p = 0; p < data1.length; p++) {  //surgery单独列出
                                for (var q = 0; q < surgery.length; q++) {
                                    if (data1[p].HADM_ID == surgery[q].HADM_ID && data1[p].MONITOR_TIME == surgery[q].MONITOR_TIME && data1[p].OPER_ID == surgery[q].OPER_ID) surgeryFlag = 1;
                                }
                                if (surgeryFlag == 0) surgery.push({
                                    HADM_ID: data1[p].HADM_ID,
                                    MONITOR_TIME: data1[p].MONITOR_TIME,
                                    OPER_ID: data1[p].OPER_ID
                                });
                                surgeryFlag = 0;
                            }
                        //distinct operation id
                        //只保留起始和结束的时间点
                            var hadmid = [data1[0].HADM_ID]
                            var operid = [data1[0].OPER_ID];
                            var surgery_s = [data1[0].MONITOR_TIME];
                            var surgery_e = [];

                            for (var s = 0; s < surgery.length; s++) {
                                if (in_array(surgery[s].OPER_ID, operid) == -1) {
                                    hadmid.push(surgery[s].HADM_ID)
                                    operid.push(surgery[s].OPER_ID);
                                    surgery_s.push(surgery[s].MONITOR_TIME);
                                    surgery_e.push(surgery[s - 1].MONITOR_TIME);
                                } else {
                                    continue;
                                }
                            }
                            surgery_e.push(surgery[surgery.length - 1].MONITOR_TIME);

                            for (var s = 0; s < operid.length; s++) {
                                dataset.push({
                                    start: new Date(Number(chGMT(surgery_s[s]).slice(0, 4)), Number(chGMT(surgery_s[s]).slice(5, 7) - 1), Number(chGMT(surgery_s[s]).slice(8, 10)), Number(chGMT(surgery_s[s]).slice(11, 13)), Number(chGMT(surgery_s[s]).slice(14, 16)), Number(chGMT(surgery_s[s]).slice(17, 19))),
                                    //e.g. 'start': new Date(2012,7,29),调整GMT时间
                                    content: 'Operation_id=' + operid[s] + '<br><button onclick="search_graph_surgeryvital(' + hadmid[s] + ',' + operid[s] + ')">surgery vitals</button>',
                                    title: 'Duration: From' + Number(chGMT(surgery_s[s]).slice(0, 4)) + '.' + Number(chGMT(surgery_s[s]).slice(5, 7)) + '.' + Number(chGMT(surgery_s[s]).slice(8, 10)) + ' ' + chGMT(surgery_s[s]).slice(11, 13) + ':' + chGMT(surgery_s[s]).slice(14, 16) + ':' + chGMT(surgery_s[s]).slice(17, 19) + ' To ' + Number(chGMT(surgery_e[s]).slice(0, 4)) + '.' + Number(chGMT(surgery_e[s]).slice(5, 7)) + '.' + Number(chGMT(surgery_e[s]).slice(8, 10)) + ' ' + chGMT(surgery_e[s]).slice(11, 13) + ':' + chGMT(surgery_e[s]).slice(14, 16) + ':' + chGMT(surgery_e[s]).slice(17, 19),
                                    className: 'lightgreen',
                                    group: 2
                                });

                            }

                            var groups = new vis.DataSet([
                                {id: 0, content: 'Admission<br>&Discharge', value: 4},
                                {id: 1, content: 'Transfers', value: 3},
                                {id: 2, content: 'Surgery', value: 2},
                                {id: 3, content: 'ICUSTAY<br>' + 'ID', value: 1},
                                {id: 4, content: 'HADM<br>' + 'ID', value: 0}

                            ]);
                        }

                        //无surgery记录
                        else{
                            var groups = new vis.DataSet([
                                {id: 0, content: 'Admission<br>&Discharge', value: 4},
                                {id: 1, content: 'Transfers', value: 3},
                                // {id: 2, content: 'Surgery', value: 2},
                                {id: 3, content: 'ICUSTAY<br>' + 'ID', value: 1},
                                {id: 4, content: 'HADM<br>' + 'ID', value: 0}

                            ]);

                        }


                        // for (var s = 0; s < surgery_e.length; s++) {
                        //     dataset.push({
                        //         start: new Date(Number(chGMT(surgery_e[s]).slice(0, 4)), Number(chGMT(surgery_e[s]).slice(5, 7) - 1), Number(chGMT(surgery_e[s]).slice(8, 10)), Number(chGMT(surgery_e[s]).slice(11, 13)), Number(chGMT(surgery_e[s]).slice(14, 16)), Number(chGMT(surgery_e[s]).slice(17, 19))),
                        //         //e.g. 'start': new Date(2012,7,29),调整GMT时间
                        //         content: 'Finished:operation_id=' + operid[s],
                        //         title: 'Time:' + Number(chGMT(surgery_e[s]).slice(0, 4)) + '.' + Number(chGMT(surgery_e[s]).slice(5, 7)) + '.' + Number(chGMT(surgery_e[s]).slice(8, 10)) + ' ' + chGMT(surgery_e[s]).slice(11, 13) + ':' + chGMT(surgery_e[s]).slice(14, 16) + ':' + chGMT(surgery_e[s]).slice(17, 19),
                        //         className: 'lightgreen',
                        //         group: 2
                        //     });
                        //
                        // }


                        for (var t = 0; t < transfer.length; t++) {//icu,含对应不同IN、OUTTIME的重复id项
                            //eg
                            //    Id     In              Out
                            //    1     2001.01.01    2001.01.13
                            //    2     2002.08.04    2002.08.12
                            //    2     2002.08.12    2002.08.15
                            //    3     1998.11.06    1998.12.07


                            if (transfer[t].ICUSTAY_ID != null) {
                                icu.push({
                                    INTIME: transfer[t].INTIME,
                                    OUTTIME: transfer[t].OUTTIME,
                                    ICUSTAY_ID: transfer[t].ICUSTAY_ID

                                })
                            }


                            if (transfer[t].EVENTTYPE == 'admit' || transfer[t].EVENTTYPE == 'discharge') {//admit discharge


                                if (transfer[t].EVENTTYPE == 'admit') {//作为每次入院进程的background标注
                                    admit.push({
                                        HADM_ID: transfer[t].HADM_ID,
                                        EVENTTYPE: transfer[t].EVENTTYPE,
                                        INTIME: transfer[t].INTIME
                                    })
                                }
                                if (transfer[t].EVENTTYPE == 'discharge') {//作为每次出院进程的background标注
                                    discharge.push({
                                        HADM_ID: transfer[t].HADM_ID,
                                        EVENTTYPE: transfer[t].EVENTTYPE,
                                        OUTTIME: transfer[t].OUTTIME
                                    })
                                }

                                //由于unit和ward有null的情况 所以要分条件push
                                if (transfer[t].EVENTTYPE == 'transfer') {
                                    dataset.push({
                                        start: new Date(Number(chGMT(transfer[t].INTIME).slice(0, 4)), Number(chGMT(transfer[t].INTIME).slice(5, 7) - 1), Number(chGMT(transfer[t].INTIME).slice(8, 10)), Number(chGMT(transfer[t].INTIME).slice(11, 13)), Number(chGMT(transfer[t].INTIME).slice(14, 16)), Number(chGMT(transfer[t].INTIME).slice(17, 19))),
                                        content: transfer[t].EVENTTYPE + '<br>to Unit ' + transfer[t].CURR_CAREUNIT + ' Ward ' + transfer[t].CURR_WARDID,
                                        title: 'Time:' + Number(chGMT(transfer[t].INTIME).slice(0, 4)) + '.' + Number(chGMT(transfer[t].INTIME).slice(5, 7)) + '.' + Number(chGMT(transfer[t].INTIME).slice(8, 10)) + ' ' + chGMT(transfer[t].INTIME).slice(11, 13) + ':' + chGMT(transfer[t].INTIME).slice(14, 16) + ':' + chGMT(transfer[t].INTIME).slice(17, 19),
                                        className: 'red',
                                        group: 0
                                    });
                                }

                                if (transfer[t].EVENTTYPE == 'admit') {
                                    dataset.push({
                                        start: new Date(Number(chGMT(transfer[t].INTIME).slice(0, 4)), Number(chGMT(transfer[t].INTIME).slice(5, 7) - 1), Number(chGMT(transfer[t].INTIME).slice(8, 10)), Number(chGMT(transfer[t].INTIME).slice(11, 13)), Number(chGMT(transfer[t].INTIME).slice(14, 16)), Number(chGMT(transfer[t].INTIME).slice(17, 19))),
                                        content: transfer[t].EVENTTYPE + '<br>in Unit ' + transfer[t].CURR_CAREUNIT,
                                        title: 'Time:' + Number(chGMT(transfer[t].INTIME).slice(0, 4)) + '.' + Number(chGMT(transfer[t].INTIME).slice(5, 7)) + '.' + Number(chGMT(transfer[t].INTIME).slice(8, 10)) + ' ' + chGMT(transfer[t].INTIME).slice(11, 13) + ':' + chGMT(transfer[t].INTIME).slice(14, 16) + ':' + chGMT(transfer[t].INTIME).slice(17, 19),
                                        className: 'red',
                                        group: 0
                                    });
                                }
                                if (transfer[t].EVENTTYPE == 'discharge') {
                                    if ((transfer[t].OUTTIME) != null) { //存在DISCHTIME为空的情况
                                        dataset.push({
                                            start: new Date(Number(chGMT(transfer[t].OUTTIME).slice(0, 4)), Number(chGMT(transfer[t].OUTTIME).slice(5, 7) - 1), Number(chGMT(transfer[t].OUTTIME).slice(8, 10)), Number(chGMT(transfer[t].OUTTIME).slice(11, 13)), Number(chGMT(transfer[t].OUTTIME).slice(14, 16)), Number(chGMT(transfer[t].OUTTIME).slice(17, 19))),
                                            content: transfer[t].EVENTTYPE + '<br>from Unit ' + transfer[t].CURR_CAREUNIT,
                                            title: 'Time:' + Number(chGMT(transfer[t].OUTTIME).slice(0, 4)) + '.' + Number(chGMT(transfer[t].OUTTIME).slice(5, 7)) + '.' + Number(chGMT(transfer[t].OUTTIME).slice(8, 10)) + ' ' + chGMT(transfer[t].OUTTIME).slice(11, 13) + ':' + chGMT(transfer[t].OUTTIME).slice(14, 16) + ':' + chGMT(transfer[t].OUTTIME).slice(17, 19),
                                            className: 'red',
                                            group: 0
                                        });
                                    }

                                }

                            } else {//transfer
                                //同样需要unit和ward是否为null的判定
                                if (transfer[t].CURR_CAREUNIT != null && transfer[t].CURR_WARDID != null) {
                                    dataset.push({
                                        start: new Date(Number(chGMT(transfer[t].INTIME).slice(0, 4)), Number(chGMT(transfer[t].INTIME).slice(5, 7) - 1), Number(chGMT(transfer[t].INTIME).slice(8, 10)), Number(chGMT(transfer[t].INTIME).slice(11, 13)), Number(chGMT(transfer[t].INTIME).slice(14, 16)), Number(chGMT(transfer[t].INTIME).slice(17, 19))),
                                        content: 'Transfer to Unit ' + transfer[t].CURR_CAREUNIT + ' Ward ' + transfer[t].CURR_WARDID,
                                        title: 'Time:' + Number(chGMT(transfer[t].INTIME).slice(0, 4)) + '.' + Number(chGMT(transfer[t].INTIME).slice(5, 7)) + '.' + Number(chGMT(transfer[t].INTIME).slice(8, 10)) + ' ' + chGMT(transfer[t].INTIME).slice(11, 13) + ':' + chGMT(transfer[t].INTIME).slice(14, 16) + ':' + chGMT(transfer[t].INTIME).slice(17, 19),
                                        group: 1
                                    });
                                } else if (transfer[t].CURR_CAREUNIT == null && transfer[t].CURR_WARDID != null) {
                                    dataset.push({
                                        start: new Date(Number(chGMT(transfer[t].INTIME).slice(0, 4)), Number(chGMT(transfer[t].INTIME).slice(5, 7) - 1), Number(chGMT(transfer[t].INTIME).slice(8, 10)), Number(chGMT(transfer[t].INTIME).slice(11, 13)), Number(chGMT(transfer[t].INTIME).slice(14, 16)), Number(chGMT(transfer[t].INTIME).slice(17, 19))),
                                        content: 'Transfer to Ward ' + transfer[t].CURR_WARDID,
                                        title: 'Time:' + Number(chGMT(transfer[t].INTIME).slice(0, 4)) + '.' + Number(chGMT(transfer[t].INTIME).slice(5, 7)) + '.' + Number(chGMT(transfer[t].INTIME).slice(8, 10)) + ' ' + chGMT(transfer[t].INTIME).slice(11, 13) + ':' + chGMT(transfer[t].INTIME).slice(14, 16) + ':' + chGMT(transfer[t].INTIME).slice(17, 19),
                                        group: 1
                                    });
                                } else if (transfer[t].CURR_CAREUNIT != null && transfer[t].CURR_WARDID == null) {
                                    dataset.push({
                                        start: new Date(Number(chGMT(transfer[t].INTIME).slice(0, 4)), Number(chGMT(transfer[t].INTIME).slice(5, 7) - 1), Number(chGMT(transfer[t].INTIME).slice(8, 10)), Number(chGMT(transfer[t].INTIME).slice(11, 13)), Number(chGMT(transfer[t].INTIME).slice(14, 16)), Number(chGMT(transfer[t].INTIME).slice(17, 19))),
                                        content: 'Transfer to Unit ' + transfer[t].CURR_CAREUNIT,
                                        title: 'Time:' + Number(chGMT(transfer[t].INTIME).slice(0, 4)) + '.' + Number(chGMT(transfer[t].INTIME).slice(5, 7)) + '.' + Number(chGMT(transfer[t].INTIME).slice(8, 10)) + ' ' + chGMT(transfer[t].INTIME).slice(11, 13) + ':' + chGMT(transfer[t].INTIME).slice(14, 16) + ':' + chGMT(transfer[t].INTIME).slice(17, 19),
                                        group: 1
                                    });
                                } else {
                                    dataset.push({
                                        start: new Date(Number(chGMT(transfer[t].INTIME).slice(0, 4)), Number(chGMT(transfer[t].INTIME).slice(5, 7) - 1), Number(chGMT(transfer[t].INTIME).slice(8, 10)), Number(chGMT(transfer[t].INTIME).slice(11, 13)), Number(chGMT(transfer[t].INTIME).slice(14, 16)), Number(chGMT(transfer[t].INTIME).slice(17, 19))),
                                        title: 'Time:' + Number(chGMT(transfer[t].INTIME).slice(0, 4)) + '.' + Number(chGMT(transfer[t].INTIME).slice(5, 7)) + '.' + Number(chGMT(transfer[t].INTIME).slice(8, 10)) + ' ' + chGMT(transfer[t].INTIME).slice(11, 13) + ':' + chGMT(transfer[t].INTIME).slice(14, 16) + ':' + chGMT(transfer[t].INTIME).slice(17, 19),
                                        group: 1
                                    });
                                }

                            }


                        }


                        //icu
                        //    Id     In              Out
                        //    1     2001.01.01    2001.01.13
                        //    2     2002.08.04    2002.08.12
                        //    2     2002.08.12    2002.08.15
                        //    3     1998.11.06    1998.12.07


                        var icustayId = [icu[0].ICUSTAY_ID];

                        for (var u = 0; u < icu.length; u++) {
                            var icuflag = 0;
                            //icuid 1,2,3
                            for (var v = 0; v < icustayId.length; v++) {
                                if (icu[u].ICUSTAY_ID == icustayId[v]) {
                                    icuflag = 1
                                }
                            }
                            if (icuflag == 0) {
                                icustayId.push(icu[u].ICUSTAY_ID)
                            }
                        }


                        for (var v = 0; v < icustayId.length; v++) {
                            var intime = [];
                            var outtime = [];
                            //搜索每个icuid对应的in和out序列 eg for id=2:
                            //          intime         outtime
                            //         2002.08.04    2002.08.12
                            //         2002.08.12    2002.08.15
                            for (var u = 0; u < icu.length; u++) {
                                if (icu[u].ICUSTAY_ID == icustayId[v]) {
                                    intime.push(icu[u].INTIME);
                                    outtime.push(icu[u].OUTTIME);
                                }
                            }

                            icustay.push({
                                INTIME: intime[0],
                                OUTTIME: outtime[outtime.length - 1],
                                ICUSTAY_ID: icustayId[v]
                            })

                        }


                        if (admit.length == discharge.length) {//完整入院+出院，background group=0+1+2+3+4
                            for (var o = 0; o < admit.length; o++) {

                                dataset.push(
                                    {
                                        start: new Date(Number(chGMT(admit[o].INTIME).slice(0, 4)), Number(chGMT(admit[o].INTIME).slice(5, 7) - 1), Number(chGMT(admit[o].INTIME).slice(8, 10)), Number(chGMT(admit[o].INTIME).slice(11, 13)), Number(chGMT(admit[o].INTIME).slice(14, 16)), Number(chGMT(admit[o].INTIME).slice(17, 19))),
                                        end: new Date(Number(chGMT(discharge[o].OUTTIME).slice(0, 4)), Number(chGMT(discharge[o].OUTTIME).slice(5, 7) - 1), Number(chGMT(discharge[o].OUTTIME).slice(8, 10)), Number(chGMT(discharge[o].OUTTIME).slice(11, 13)), Number(chGMT(discharge[o].OUTTIME).slice(14, 16)), Number(chGMT(discharge[o].OUTTIME).slice(17, 19))),
                                        //content: '<br><a href="/search/graph_lab?q='+admit[o].HADM_ID+'" target="_blank">'+'HADM ID: '+admit[o].HADM_ID+'</a>'
                                        content: 'HADM ID: ' + admit[o].HADM_ID + '<br><button onclick= "search_graph_lab(' + admit[o].HADM_ID + '); ">' + 'lab test' + '</button><button onclick= search_graph_emrsymptom(' + admit[o].HADM_ID + ')>' + 'emr symptoms' + '</button>',
                                        type: 'background',
                                        className: 'negative',
                                        group: 4
                                    }
                                )
                                dataset.push(
                                    {
                                        start: new Date(Number(chGMT(admit[o].INTIME).slice(0, 4)), Number(chGMT(admit[o].INTIME).slice(5, 7) - 1), Number(chGMT(admit[o].INTIME).slice(8, 10)), Number(chGMT(admit[o].INTIME).slice(11, 13)), Number(chGMT(admit[o].INTIME).slice(14, 16)), Number(chGMT(admit[o].INTIME).slice(17, 19))),
                                        end: new Date(Number(chGMT(discharge[o].OUTTIME).slice(0, 4)), Number(chGMT(discharge[o].OUTTIME).slice(5, 7) - 1), Number(chGMT(discharge[o].OUTTIME).slice(8, 10)), Number(chGMT(discharge[o].OUTTIME).slice(11, 13)), Number(chGMT(discharge[o].OUTTIME).slice(14, 16)), Number(chGMT(discharge[o].OUTTIME).slice(17, 19))),
                                        type: 'background',
                                        className: 'negative',
                                        group: 3
                                    }
                                )
                                dataset.push(
                                    {
                                        start: new Date(Number(chGMT(admit[o].INTIME).slice(0, 4)), Number(chGMT(admit[o].INTIME).slice(5, 7) - 1), Number(chGMT(admit[o].INTIME).slice(8, 10)), Number(chGMT(admit[o].INTIME).slice(11, 13)), Number(chGMT(admit[o].INTIME).slice(14, 16)), Number(chGMT(admit[o].INTIME).slice(17, 19))),
                                        end: new Date(Number(chGMT(discharge[o].OUTTIME).slice(0, 4)), Number(chGMT(discharge[o].OUTTIME).slice(5, 7) - 1), Number(chGMT(discharge[o].OUTTIME).slice(8, 10)), Number(chGMT(discharge[o].OUTTIME).slice(11, 13)), Number(chGMT(discharge[o].OUTTIME).slice(14, 16)), Number(chGMT(discharge[o].OUTTIME).slice(17, 19))),
                                        type: 'background',
                                        className: 'negative',
                                        group: 2
                                    }
                                )
                                dataset.push(
                                    {
                                        start: new Date(Number(chGMT(admit[o].INTIME).slice(0, 4)), Number(chGMT(admit[o].INTIME).slice(5, 7) - 1), Number(chGMT(admit[o].INTIME).slice(8, 10)), Number(chGMT(admit[o].INTIME).slice(11, 13)), Number(chGMT(admit[o].INTIME).slice(14, 16)), Number(chGMT(admit[o].INTIME).slice(17, 19))),
                                        end: new Date(Number(chGMT(discharge[o].OUTTIME).slice(0, 4)), Number(chGMT(discharge[o].OUTTIME).slice(5, 7) - 1), Number(chGMT(discharge[o].OUTTIME).slice(8, 10)), Number(chGMT(discharge[o].OUTTIME).slice(11, 13)), Number(chGMT(discharge[o].OUTTIME).slice(14, 16)), Number(chGMT(discharge[o].OUTTIME).slice(17, 19))),
                                        type: 'background',
                                        className: 'negative',
                                        group: 1
                                    }
                                )
                                dataset.push(
                                    {
                                        start: new Date(Number(chGMT(admit[o].INTIME).slice(0, 4)), Number(chGMT(admit[o].INTIME).slice(5, 7) - 1), Number(chGMT(admit[o].INTIME).slice(8, 10)), Number(chGMT(admit[o].INTIME).slice(11, 13)), Number(chGMT(admit[o].INTIME).slice(14, 16)), Number(chGMT(admit[o].INTIME).slice(17, 19))),
                                        end: new Date(Number(chGMT(discharge[o].OUTTIME).slice(0, 4)), Number(chGMT(discharge[o].OUTTIME).slice(5, 7) - 1), Number(chGMT(discharge[o].OUTTIME).slice(8, 10)), Number(chGMT(discharge[o].OUTTIME).slice(11, 13)), Number(chGMT(discharge[o].OUTTIME).slice(14, 16)), Number(chGMT(discharge[o].OUTTIME).slice(17, 19))),
                                        type: 'background',
                                        className: 'negative',
                                        group: 0
                                    }
                                )
                            }
                        }


                        if (admit.length - discharge.length == 1) {//最后一次入院未出院,background
                            for (var o = 0; o < discharge.length; o++) {
                                dataset.push(
                                    {
                                        start: new Date(Number(chGMT(admit[o].INTIME).slice(0, 4)), Number(chGMT(admit[o].INTIME).slice(5, 7) - 1), Number(chGMT(admit[o].INTIME).slice(8, 10)), Number(chGMT(admit[o].INTIME).slice(11, 13)), Number(chGMT(admit[o].INTIME).slice(14, 16)), Number(chGMT(admit[o].INTIME).slice(17, 19))),
                                        end: new Date(Number(chGMT(discharge[o].OUTTIME).slice(0, 4)), Number(chGMT(discharge[o].OUTTIME).slice(5, 7) - 1), Number(chGMT(discharge[o].OUTTIME).slice(8, 10)), Number(chGMT(discharge[o].OUTTIME).slice(11, 13)), Number(chGMT(discharge[o].OUTTIME).slice(14, 16)), Number(chGMT(discharge[o].OUTTIME).slice(17, 19))),
                                        content: 'HADM ID: ' + admit[o].HADM_ID + '<br><button  onclick= "search_graph_lab(' + admit[o].HADM_ID + ');">' + 'lab test' + '</button><button id="buttonemrsymptom" onclick= search_graph_emrsymptom(' + admit[o].HADM_ID + ')>' + 'emr symptoms' + '</button>',
                                        type: 'background',
                                        className: 'negative',
                                        group: 4
                                    }
                                )
                                dataset.push(
                                    {
                                        start: new Date(Number(chGMT(admit[o].INTIME).slice(0, 4)), Number(chGMT(admit[o].INTIME).slice(5, 7) - 1), Number(chGMT(admit[o].INTIME).slice(8, 10)), Number(chGMT(admit[o].INTIME).slice(11, 13)), Number(chGMT(admit[o].INTIME).slice(14, 16)), Number(chGMT(admit[o].INTIME).slice(17, 19))),
                                        end: new Date(Number(chGMT(discharge[o].OUTTIME).slice(0, 4)), Number(chGMT(discharge[o].OUTTIME).slice(5, 7) - 1), Number(chGMT(discharge[o].OUTTIME).slice(8, 10)), Number(chGMT(discharge[o].OUTTIME).slice(11, 13)), Number(chGMT(discharge[o].OUTTIME).slice(14, 16)), Number(chGMT(discharge[o].OUTTIME).slice(17, 19))),
                                        type: 'background',
                                        className: 'negative',
                                        group: 3
                                    }
                                )
                                dataset.push(
                                    {
                                        start: new Date(Number(chGMT(admit[o].INTIME).slice(0, 4)), Number(chGMT(admit[o].INTIME).slice(5, 7) - 1), Number(chGMT(admit[o].INTIME).slice(8, 10)), Number(chGMT(admit[o].INTIME).slice(11, 13)), Number(chGMT(admit[o].INTIME).slice(14, 16)), Number(chGMT(admit[o].INTIME).slice(17, 19))),
                                        end: new Date(Number(chGMT(discharge[o].OUTTIME).slice(0, 4)), Number(chGMT(discharge[o].OUTTIME).slice(5, 7) - 1), Number(chGMT(discharge[o].OUTTIME).slice(8, 10)), Number(chGMT(discharge[o].OUTTIME).slice(11, 13)), Number(chGMT(discharge[o].OUTTIME).slice(14, 16)), Number(chGMT(discharge[o].OUTTIME).slice(17, 19))),
                                        type: 'background',
                                        className: 'negative',
                                        group: 2
                                    }
                                )
                                dataset.push(
                                    {
                                        start: new Date(Number(chGMT(admit[o].INTIME).slice(0, 4)), Number(chGMT(admit[o].INTIME).slice(5, 7) - 1), Number(chGMT(admit[o].INTIME).slice(8, 10)), Number(chGMT(admit[o].INTIME).slice(11, 13)), Number(chGMT(admit[o].INTIME).slice(14, 16)), Number(chGMT(admit[o].INTIME).slice(17, 19))),
                                        end: new Date(Number(chGMT(discharge[o].OUTTIME).slice(0, 4)), Number(chGMT(discharge[o].OUTTIME).slice(5, 7) - 1), Number(chGMT(discharge[o].OUTTIME).slice(8, 10)), Number(chGMT(discharge[o].OUTTIME).slice(11, 13)), Number(chGMT(discharge[o].OUTTIME).slice(14, 16)), Number(chGMT(discharge[o].OUTTIME).slice(17, 19))),
                                        type: 'background',
                                        className: 'negative',
                                        group: 1
                                    }
                                )
                                dataset.push(
                                    {
                                        start: new Date(Number(chGMT(admit[o].INTIME).slice(0, 4)), Number(chGMT(admit[o].INTIME).slice(5, 7) - 1), Number(chGMT(admit[o].INTIME).slice(8, 10)), Number(chGMT(admit[o].INTIME).slice(11, 13)), Number(chGMT(admit[o].INTIME).slice(14, 16)), Number(chGMT(admit[o].INTIME).slice(17, 19))),
                                        end: new Date(Number(chGMT(discharge[o].OUTTIME).slice(0, 4)), Number(chGMT(discharge[o].OUTTIME).slice(5, 7) - 1), Number(chGMT(discharge[o].OUTTIME).slice(8, 10)), Number(chGMT(discharge[o].OUTTIME).slice(11, 13)), Number(chGMT(discharge[o].OUTTIME).slice(14, 16)), Number(chGMT(discharge[o].OUTTIME).slice(17, 19))),
                                        type: 'background',
                                        className: 'negative',
                                        group: 0

                                    }
                                )
                            }

                        }


                        for (var o = 0; o < icustay.length; o++) {//icustay,background,考虑覆盖所以放在hadm下面
                            dataset.push(
                                {
                                    start: new Date(Number(chGMT(icustay[o].INTIME).slice(0, 4)), Number(chGMT(icustay[o].INTIME).slice(5, 7) - 1), Number(chGMT(icustay[o].INTIME).slice(8, 10)), Number(chGMT(icustay[o].INTIME).slice(11, 13)), Number(chGMT(icustay[o].INTIME).slice(14, 16)), Number(chGMT(icustay[o].INTIME).slice(17, 19))),
                                    end: new Date(Number(chGMT(icustay[o].OUTTIME).slice(0, 4)), Number(chGMT(icustay[o].OUTTIME).slice(5, 7) - 1), Number(chGMT(icustay[o].OUTTIME).slice(8, 10)), Number(chGMT(icustay[o].OUTTIME).slice(11, 13)), Number(chGMT(icustay[o].OUTTIME).slice(14, 16)), Number(chGMT(icustay[o].OUTTIME).slice(17, 19))),
                                    content: 'ICUSTAY ID: ' + icustay[o].ICUSTAY_ID + '<br><button  onclick= "search_graph_sign(' + icustay[o].ICUSTAY_ID + ')">' + 'signs' + '</button><button  onclick= "search_graph_med(' + icustay[o].ICUSTAY_ID + ')">' + 'medication' + '</button>',
                                    type: 'background',
                                    group: 3
                                }
                            )
                            dataset.push(
                                {
                                    start: new Date(Number(chGMT(icustay[o].INTIME).slice(0, 4)), Number(chGMT(icustay[o].INTIME).slice(5, 7) - 1), Number(chGMT(icustay[o].INTIME).slice(8, 10)), Number(chGMT(icustay[o].INTIME).slice(11, 13)), Number(chGMT(icustay[o].INTIME).slice(14, 16)), Number(chGMT(icustay[o].INTIME).slice(17, 19))),
                                    end: new Date(Number(chGMT(icustay[o].OUTTIME).slice(0, 4)), Number(chGMT(icustay[o].OUTTIME).slice(5, 7) - 1), Number(chGMT(icustay[o].OUTTIME).slice(8, 10)), Number(chGMT(icustay[o].OUTTIME).slice(11, 13)), Number(chGMT(icustay[o].OUTTIME).slice(14, 16)), Number(chGMT(icustay[o].OUTTIME).slice(17, 19))),
                                    type: 'background',
                                    group: 2
                                }
                            )
                            dataset.push(
                                {
                                    start: new Date(Number(chGMT(icustay[o].INTIME).slice(0, 4)), Number(chGMT(icustay[o].INTIME).slice(5, 7) - 1), Number(chGMT(icustay[o].INTIME).slice(8, 10)), Number(chGMT(icustay[o].INTIME).slice(11, 13)), Number(chGMT(icustay[o].INTIME).slice(14, 16)), Number(chGMT(icustay[o].INTIME).slice(17, 19))),
                                    end: new Date(Number(chGMT(icustay[o].OUTTIME).slice(0, 4)), Number(chGMT(icustay[o].OUTTIME).slice(5, 7) - 1), Number(chGMT(icustay[o].OUTTIME).slice(8, 10)), Number(chGMT(icustay[o].OUTTIME).slice(11, 13)), Number(chGMT(icustay[o].OUTTIME).slice(14, 16)), Number(chGMT(icustay[o].OUTTIME).slice(17, 19))),
                                    type: 'background',
                                    group: 1
                                }
                            )
                            dataset.push(
                                {
                                    start: new Date(Number(chGMT(icustay[o].INTIME).slice(0, 4)), Number(chGMT(icustay[o].INTIME).slice(5, 7) - 1), Number(chGMT(icustay[o].INTIME).slice(8, 10)), Number(chGMT(icustay[o].INTIME).slice(11, 13)), Number(chGMT(icustay[o].INTIME).slice(14, 16)), Number(chGMT(icustay[o].INTIME).slice(17, 19))),
                                    end: new Date(Number(chGMT(icustay[o].OUTTIME).slice(0, 4)), Number(chGMT(icustay[o].OUTTIME).slice(5, 7) - 1), Number(chGMT(icustay[o].OUTTIME).slice(8, 10)), Number(chGMT(icustay[o].OUTTIME).slice(11, 13)), Number(chGMT(icustay[o].OUTTIME).slice(14, 16)), Number(chGMT(icustay[o].OUTTIME).slice(17, 19))),
                                    type: 'background',
                                    group: 0
                                }
                            )

                        }


                        var chartdata = new vis.DataSet(dataset);
                        // specify options
                        var options = {
                            editable: false,
                            // zoomKey: 'ctrlKey',
                            // option groupOrder can be a property name or a sort function
                            // the sort function must compare two groups and return a value
                            //     > 0 when a > b
                            //     < 0 when a < b
                            //       0 when a == b
                            groupOrder: function (a, b) {
                                return a.value - b.value;
                            }


                        };


                        var html0 = "<span>Supports zooming & moving with the mouse.Click to <input type='button' value='Fit all items' id='fit'></span><br><br>"
                        $("#chartdiv").append($(html0));// //fit items button


                        document.getElementById('fit').onclick = function () {
                            timeline.fit();
                        };


                        // create the timeline

                        //Method 1:
                        // var container = document.getElementById('chartdiv');
                        // var timeline = new vis.Timeline(container);
                        // timeline.setOptions(options);
                        // timeline.setGroups(groups);
                        // timeline.setItems(chartdata);

                        //Method 2:
                        var container = document.getElementById('chartdiv');
                        var timeline = new vis.Timeline(container, chartdata, options, groups);


                    }
                }

            })


        }

        // function mutebutton_lab1() {
        //     $("#button_lab1").attr("disabled", true);
        //     $("#button_lab2").attr("disabled", false);
        // }
        //
        // function mutebutton_lab2() {
        //     $("#button_lab2").attr("disabled", true);
        //     $("#button_lab1").attr("disabled", false);
        // }


        function search_graph_lab(Term1) {
        //var Term =
        !{JSON.stringify(term)};
            $.ajax({
                url: "/search/graph_lab/list",
                type: "POST",
                data: {term: Term1},

                success: function (data) {

                    if (data == '') {
                        alert("No or lack of relevant data!" + "\n" + "Click to close the message box.");
                    } else {
                        //alert("success");


                        var item = [];
                        var distinctItemId = [];
                        var distinctLabel = [];

                        var id = [];
                        var label = [];
                        var charttime = [];
                        var value = [];
                        var unit = [];
                        var flag = [];


                        var seriesArr = [];

                        for (var i = 0; i < data.length; i++) {//distinct itemid


                            id.push(data[i].ITEM_ID);
                            label.push(data[i].LABEL);
                            charttime.push(data[i].CHARTTIME);
                            value.push(data[i].VALUE);


                            if (!item[data[i].ITEMID]) {
                                distinctItemId.push(data[i].ITEMID);
                                distinctLabel.push(data[i].LABEL);
                                item[data[i].ITEMID] = true;
                            }
                        }


                        for (var j = 0; j < distinctItemId.length; j++) {

                            var labTestData = [];
                            var k = 0;//清空

                            for (var r = 0; r < data.length; r++) {

                                if (data[r].ITEMID == distinctItemId[j]) {//r=0：所有item0的数据循环存储

                                    labTestData[k] = {
                                        x: Date.UTC(chGMT(data[r].CHARTTIME).slice(0, 4), chGMT(data[r].CHARTTIME).slice(5, 7) - 1, chGMT(data[r].CHARTTIME).slice(8, 10), chGMT(data[r].CHARTTIME).slice(11, 13), chGMT(data[r].CHARTTIME).slice(14, 16), chGMT(data[r].CHARTTIME).slice(17, 19)),
                                        y: Number(data[r].VALUE),
                                        unit: data[r].VALUEUOM,
                                        flag: data[r].FLAG
                                    }
                                    k++;
                                }
                            }

                            if (j < 10) {//区分是否默认可见
                                seriesArr.push({//存储完毕push到series，item0完毕
                                    name: distinctLabel[j],
                                    data: labTestData,
                                    // unit:labTestData[0].data[0].unit,
                                    color: Highcharts.getOptions().colors[j],
                                    visible: true
                                });
                            } else {
                                seriesArr.push({
                                    name: distinctLabel[j],
                                    data: labTestData,
                                    color: Highcharts.getOptions().colors[j],
                                    visible: false
                                });

                            }


                        }


                        //////////// LAB TEST DATA ////////////

                        //同步缩放效果
                        function syncExtremes(e) {
                            var thisChart = this.chart;
                            if (e.trigger !== 'syncExtremes') {
                                Highcharts.each(Highcharts.charts, function (chart) {
                                    if (chart !== thisChart) {
                                        if (chart.xAxis[0].setExtremes) {
                                            chart.xAxis[0].setExtremes(e.min, e.max, undefined, false, {trigger: 'syncExtremes'});
                                        }
                                    }
                                });
                            }
                        }

                        Highcharts.chart('labchart', {
                            chart: {
                                type: 'spline',
                                marginLeft: 150,
                                zoomType: 'xy',
                                panning: true,
                                panKey: 'ctrl'
                            },


                            title: {
                                text: 'LAB TEST-HADMID: ' + Term1
                            },
                            subtitle: {
                                text: 'Drag to select the zoom area; Press ctrl to pan the chart left or right; Click on the legend to hide or resume display.'
                            },

                            xAxis: {
                                type: 'datetime',
                                events: {
                                    setExtremes: syncExtremes
                                },
                                title: {
                                    text: 'Time In Hospital'
                                }
                            },

                            yAxis: [{
                                title: {
                                    text: 'Value'
                                },
                                tickInterval: 1

                            }],
                            tooltip: {//label样式
                                headerFormat: '<b>Item:{series.name}</b><br>',
                                pointFormat: '<b>Result:</b>{point.y} {point.unit}<br><b>Flag:</b>{point.flag}<br>{point.x:%A,%b.%e,%Y,%H:%M:%S}',
                                positioner: function () {//固定标签显示位置
                                    return {x: this.chart.chartWidth - this.label.width - 1, y: 0};//x: this.chart.chartWidth - this.label.width 表示right aligned；y: -1 表示align to title
                                },
                                // shadow: false,
                                // shape: 'round',
                                // borderWidth: 0,
                                // backgroundColor: 'rgba(0,0,0,0.2)',
                                crosshairs: [{            // 设置准星线样式
                                    width: 1,
                                    color: "#006cee",
                                    dashStyle: 'longdashdot'

                                }, {
                                    width: 1,
                                    color: "#006cee",
                                    dashStyle: 'longdashdot'
                                }]
                            },
                            legend: {//图例右侧显示
                                layout: 'vertical',
                                align: 'right',
                                verticalAlign: 'middle'
                            },

                            plotOptions: {//line的图例标线
                                series: {
                                    label: {
                                        connectorAllowed: false
                                    }
                                },
                                spline: {//标志点
                                    marker: {
                                        enabled: true
                                    }
                                }
                            },


                            series: seriesArr


                        });


                    }
                }

            })
        }



        function search_graph_sign(Term2) {
            //var Term =
            !{JSON.stringify(term)};
            $.ajax({
                url: "/search/graph_sign/list",
                type: "POST",
                data: {term: Term2},

                success: function (data) {

                    if (data == '') {
                        alert("No or lack of relevant data!" + "\n" + "Click to close the message box.");
                        // window.close();

                    } else {


                        //alert("Success!");

                        var sign_time = [];//体征记录时间，横轴
                        var sign_arr = [];
                        var sign_arr1 = [];//UrineOutput
                        var sign_arr2 = [];//DiastolicPressure
                        var sign_arr3 = [];//SystolicPressure
                        var sign_arr4 = [];//Temperature
                        var sign_arr5 = [];//OxygenSaturation
                        var sign_arr6 = [];//BloodGlucose
                        var sign_arr7 = [];//HeartRate
                        var sign_arr8 = [];//RespiratoryRate
                        var sign_arr9 = [];//Pulse
                        var sign_arr10 = [];//Excrement
                        var sign_arr11 = [];//Input
                        var sign_arr12 = [];//Output
                        var sign_arr13 = [];//PainScore
                        var sign_arr14 = [];//Height
                        var sign_arr15 = [];//Weight
                        var sign_arr16 = [];//AbdominalGirth
                        var sign_arr17 = [];//BoxTemperature
                        var sign_arr18 = [];//Calories
                        var sign_arr19 = [];//HeadCircumference
                        var k1 = 0;
                        var k2 = 0;
                        var k3 = 0;
                        var k4 = 0;
                        var k5 = 0;
                        var k6 = 0;
                        var k7 = 0;
                        var k8 = 0;
                        var k9 = 0;
                        var k10 = 0;
                        var k11 = 0;
                        var k12 = 0;
                        var k13 = 0;
                        var k14 = 0;
                        var k15 = 0;
                        var k16 = 0;
                        var k17 = 0;
                        var k18 = 0;
                        var k19 = 0;


                        //////////// VITAL SIGN DATA ////////////


                        sign_arr[0] = data[0];//把重复的数据去掉,sign_arr包含全部charttime的所有数据
                        sign_time[0] = sign_arr[0].CHARTTIME;
                        var s = 1;//注意s是从1开始的，p也是从1开始的
                        for (var p = 1; p < data.length; p++) {//循环将所有记录的时间加入数组，确定横轴
                            if (data[p].CHARTTIME != data[p - 1].CHARTTIME) {
                                sign_arr[s] = data[p];
                                sign_time[s] = sign_arr[s].CHARTTIME;
                                s++;
                            }
                        }


                        for (var ks = 0; ks < s; ks++) {//signarr1-signarr19代表体征检测值
                            if (sign_arr[ks].UrineOutput != null) {
                                sign_arr1[k1] = {//sign_arr的顺序另外计数
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].UrineOutput)
                                }
                                k1++;
                            }
                            if (sign_arr[ks].DiastolicPressure != null) {
                                sign_arr2[k2] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].DiastolicPressure)
                                }
                                k2++;
                            }
                            if (sign_arr[ks].SystolicPressure != null) {
                                sign_arr3[k3] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].SystolicPressure)
                                }
                                k3++;
                            }
                            if (sign_arr[ks].Temperature != null) {
                                sign_arr4[k4] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].Temperature)
                                }
                                k4++;
                            }
                            if (sign_arr[ks].OxygenSaturation != null) {
                                sign_arr5[k5] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].OxygenSaturation)
                                }
                                k5++;
                            }
                            if (sign_arr[ks].BloodGlucose != null) {
                                sign_arr6[k6] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].BloodGlucose)
                                }
                                k6++;
                            }
                            if (sign_arr[ks].HeartRate != null) {
                                sign_arr7[k7] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].HeartRate)
                                }
                                k7++;
                            }
                            if (sign_arr[ks].RespiratoryRate != null) {
                                sign_arr8[k8] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].RespiratoryRate)
                                }
                                k8++;
                            }
                            if (sign_arr[ks].Pulse != null) {
                                sign_arr9[k9] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].Pulse)
                                }
                                k9++;
                            }
                            if (sign_arr[ks].Excrement != null) {
                                sign_arr10[k10] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].Excrement)
                                }
                                k10++;
                            }
                            if (sign_arr[ks].Input != null) {
                                sign_arr11[k11] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].Input)
                                }
                                k11++;
                            }
                            if (sign_arr[ks].Output != null) {
                                sign_arr12[k12] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].Output)
                                }
                                k12++;
                            }
                            if (sign_arr[ks].PainScore != null) {
                                sign_arr13[k13] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].PainScore)
                                }
                                k13++;
                            }
                            if (sign_arr[ks].Height != null) {
                                sign_arr14[k14] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].Height)
                                }
                                k14++;
                            }
                            if (sign_arr[ks].Weight != null) {
                                sign_arr15[k15] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].Weight)
                                }
                                k15++;
                            }
                            if (sign_arr[ks].AbdominalGirth != null) {
                                sign_arr16[k16] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].AbdominalGirth)
                                }
                                k16++;
                            }
                            if (sign_arr[ks].BoxTemperature != null) {
                                sign_arr17[k17] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].BoxTemperature)
                                }
                                k17++;
                            }
                            if (sign_arr[ks].Calories != null) {
                                sign_arr18[k18] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].Calories)
                                }
                                k18++;
                            }
                            if (sign_arr[ks].HeadCircumference != null) {
                                sign_arr19[k19] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].HeadCircumference)
                                }
                                k19++;
                            }



                        }


                        /*  本例子的目的是为了演示通过 Dom 事件、Highcharts 事件、Highcharts API 来讲一个页面中的多个图表进行联动的。
                            本例通过循环创建类似的图表并绑定鼠标的滑动事件来对多个图表进行演示联动效果。*/


                        $(function () {
                            // /**
                            //  * 为了让多个图表的提示框即十字准星线能够联动，这里绑定多个图表的附件 dom 的鼠标事件进行联动
                            //  */
                            // $('#timechart1').bind('mousemove touchmove touchstart', function (e) {
                            //     var chart,
                            //         point,
                            //         i,
                            //         event;
                            //     for (i = 0; i < Highcharts.charts.length; i = i + 1) {
                            //         chart = Highcharts.charts[i];
                            //         event = chart.pointer.normalize(e.originalEvent); // Find coordinates within the chart
                            //         point = chart.series[0].searchPoint(event, true); // Get the hovered point
                            //         if (point) {
                            //             point.highlight(e);
                            //         }
                            //     }
                            // });

                            // /**
                            //  * 重写内部的方法， 这里是将提示框即十字准星的隐藏函数关闭
                            //  */
                            // Highcharts.Pointer.prototype.reset = function () {
                            //     return undefined;
                            // };
                            // /**
                            //  * 高亮当前的数据点，并设置鼠标滑动状态及绘制十字准星线
                            //  */
                            // Highcharts.Point.prototype.highlight = function (event) {
                            //     this.onMouseOver(); // 显示鼠标激活标识
                            //     this.series.chart.tooltip.refresh(this); // 显示提示框
                            //     this.series.chart.xAxis[0].drawCrosshair(event, this); // 显示十字准星线
                            // };

                            /*
                             * 同步缩放效果，即当一个图表进行了缩放效果，其他图表也进行缩放
                             */
                            function syncExtremes(e) {
                                var thisChart = this.chart;
                                if (e.trigger !== 'syncExtremes') {
                                    Highcharts.each(Highcharts.charts, function (chart) {
                                        if (chart !== thisChart) {
                                            if (chart.xAxis[0].setExtremes) {
                                                chart.xAxis[0].setExtremes(e.min, e.max, undefined, false, {trigger: 'syncExtremes'});
                                            }
                                        }
                                    });
                                }
                            }




                            //体征变化
                            Highcharts.chart('timechart1', {
                                chart: {
                                    type: 'spline',
                                    marginLeft: 150,
                                    zoomType: 'xy',
                                    panning: true,
                                    panKey: 'ctrl'

                                },
                                title: {
                                    text: 'VITAL SIGNS-ICUSTAYID: ' + Term2
                                },
                                subtitle: {
                                    text: 'Drag to select the zoom area; Press ctrl to pan the chart left or right; Click on the legend to hide or resume display.'
                                },
                                xAxis: {
                                    type: 'datetime',

                                    events: {
                                        setExtremes: syncExtremes
                                    },


                                    title: {
                                        text: 'Time In ICU'
                                    }

                                },
                                yAxis: [{
                                    title: {
                                        text: 'Measurement, Absolute Value'
                                    },
                                    //reversed: true,//y轴值上下顺序反向
                                    tickInterval: 1,
                                    min: 0
                                }],

                                tooltip: {//label样式
                                    headerFormat: '<b>{series.name}:{point.y}</b><br>',
                                    pointFormat: '{point.x:%A,%b.%e,%Y,%H:%M:%S} ',
                                    positioner: function () {//固定标签显示位置
                                        return {x: this.chart.chartWidth - this.label.width - 1, y: 0};//x: this.chart.chartWidth - this.label.width 表示right aligned；y: -1 表示align to title
                                    },
                                    // shadow: false,
                                    // shape: 'round',
                                    // borderWidth: 0,
                                    // backgroundColor: 'rgba(0,0,0,0.2)',
                                    crosshairs: [{            // 设置准星线样式
                                        width: 1,
                                        color: "#006cee",
                                        dashStyle: 'longdashdot'

                                    }, {
                                        width: 1,
                                        color: "#006cee",
                                        dashStyle: 'longdashdot'
                                    }]
                                },
                                //     % a:星期的缩写, 比如'Mon'.
                                //     % A:星期的全写, 比如'Monday'.
                                //     % d:日期的写法, 比如：01到31.
                                //     % e:日期的写法, 1到31.
                                //     % b:月的缩写, 比如'Jan'.
                                //     % B:月的全写, 比如'January'.
                                //     % m:阿拉伯月的写法, 0112.
                                //     % y:年的缩写, 比如09代表2009.
                                //     % Y:年的全写, 比如2009.
                                //     % H:两位数的24小时写法, 比如00到23.
                                //     % I:两位数的12小时写法, 00到11.
                                //     % l(L字母的小写):12小时的写法, 1到11.
                                //     % M:分钟写法, 00到59.
                                //     % p:Upper case AM or PM.
                                //     % P:Lower case AM or PM.
                                //     % S:分钟写法, 00到59

                                legend: {//图例右侧显示
                                    layout: 'vertical',
                                    align: 'right',
                                    verticalAlign: 'middle'
                                },

                                plotOptions: {//line的图例标线
                                    series: {
                                        label: {
                                            connectorAllowed: false
                                        }
                                    },
                                    spline: {//标志点
                                        marker: {
                                            enabled: true
                                        }
                                    }
                                },

                                // colors: ['#ae0000', '#ff85e5', '#036', '#ffc300', '#3ecc8c', '#6CF', '#696969', '#FF8C00'],
                                series: [
                                    {
                                        name: 'Abdominal Girth',
                                        data: sign_arr16
                                    },
                                    {
                                        name: 'Blood Glucose',
                                        data: sign_arr6
                                    },
                                    {
                                        name: 'Box Temperature',
                                        data: sign_arr17
                                    },
                                    {
                                        name: 'Calories',
                                        data: sign_arr18
                                    },
                                    {
                                        name: 'Diastolic Pressure',
                                        data: sign_arr2
                                    },
                                    {
                                        name: 'Excrement',
                                        data: sign_arr10
                                    },
                                    {
                                        name: 'Head Circumference',
                                        data: sign_arr19
                                    },
                                    {
                                        name: 'Heart Rate',
                                        data: sign_arr7
                                    },
                                    {
                                        name: 'Height',
                                        data: sign_arr14
                                    },
                                    {
                                        name: 'Input',
                                        data: sign_arr11
                                    },
                                    {
                                        name: 'Output',
                                        data: sign_arr12
                                    },
                                    {
                                        name: 'Oxygen Saturation',
                                        data: sign_arr5
                                    },
                                    {
                                        name: 'Pain Score',
                                        data: sign_arr13
                                    },
                                    {
                                        name: 'Pulse',
                                        data: sign_arr9
                                    },
                                    {
                                        name: 'Respiratory Rate',
                                        data: sign_arr8
                                    },
                                    {
                                        name: 'Systolic Pressure',
                                        data: sign_arr3
                                    },
                                    {
                                        name: 'Temperature',
                                        data: sign_arr4
                                    },
                                    {
                                        name: 'Urine Output',
                                        data: sign_arr1
                                    },
                                    {
                                        name: 'Weight',
                                        data: sign_arr15
                                    }
                                ]
                            });

                        });
                    }
                }
            })
        }



        function search_graph_med(Term2) {
            //var Term =
            !{JSON.stringify(term)};
            $.ajax({
                url: "/search/graph_med/list",
                type: "POST",
                data: {term: Term2},

                success: function (data) {

                    if (data == '') {
                        alert("No or lack of relevant data!" + "\n" + "Click to close the message box.");
                        // window.close();

                    } else {
                        //alert("Success!");
                        var drugcategory = [];
                        var drugresult = [];
                        var obj = {};
                        var arrData = [];

                        var starttime = [];
                        var endtime = [];
                        var strength = [];
                        var dosevalue = [];
                        var doseunit = [];
                        var dosechange = [];



                        ////////DRUG DATA/////////


                        var drug = [data[0]];
                        var drugflag = 0;


                        //将不同charttime同样用药的记录删掉，得到不重复的用药记录

                        for (var w = 0; w < data.length; w++) {
                            for (var o = 0; o < drug.length; o++) {
                                if (data[w].DRUG_NAME_EN == drug[o].DRUG_NAME_EN && data[w].STARTDATE == drug[o].STARTDATE && data[w].ENDDATE == drug[o].ENDDATE && data[w].PROD_STRENGTH == drug[o].PROD_STRENGTH && data[w].DOSE_VAL_RX == drug[o].DOSE_VAL_RX && data[w].DOSE_UNIT_RX == drug[o].DOSE_UNIT_RX) drugflag = 1;
                            }
                            if (drugflag == 0) drug.push(data[w]);
                            drugflag = 0;
                        }


                        var c = 0;

                        for (var q = 0; q < drug.length; q++) {
                            drugcategory[c] = [drug[q].DRUG_NAME_EN];
                            starttime[c] = [drug[q].STARTDATE];
                            if (drug[q].ENDDATE == null) endtime[c] = [drug[q].STARTDATE];
                            else endtime[c] = [drug[q].ENDDATE];
                            strength[c] = [drug[q].PROD_STRENGTH];
                            dosevalue[c] = [drug[q].DOSE_VAL_RX];
                            doseunit[c] = [drug[q].DOSE_UNIT_RX];
                            c++;
                        }

                        //删除重复元素
                        for (var i = 0; i < drug.length; i++) {

                            if (!obj[drugcategory[i]]) {
                                drugresult.push(drugcategory[i]);//drugresult存储不重复药品名
                                obj[drugcategory[i]] = true;
                            }

                        }
                        drugresult.sort(); //将药品显示按照自上至下的字母顺序重排


                        //为了比较剂量大小，需要将原数组中每一种药组合在一起再比较

                        for (var t = 0; t < drugresult.length; t++) {//遍历drugresult eg A B C D 0123
                            var samedrug = [];//每一种新的药物设一个空白数组
                            var j = 0;
                            for (var u = 0; u < c; u++) {//遍历drugcategory eg A B A C D B A 0123456
                                if (drugcategory[u][0] == drugresult[t][0]) {
                                    samedrug[j] = u;
                                    j++;//将相同药物存进来 eg A 026
                                }
                            }

                            var value = [];
                            for (var j0 = 0; j0 < j; j0++) {

                                //单位换算:g,gm,mg,mg/ml,mg/kg,mg/hr,mg/min,mg/day,mg/24h,mg/kg/hr - mcg,mcg/ml,mcg/kg,mcg/h,mcg/kg/min

                                value[j0] = parseFloat(dosevalue[samedrug[j0]][0]);
                                if (doseunit[samedrug[j0]][0] == "g") value[j0] = value[j0] * 1000000;
                                else if (doseunit[samedrug[j0]][0] == "mg" || doseunit[samedrug[j0]][0] == "mg/ml" || doseunit[samedrug[j0]][0] == "mg/kg" || doseunit[samedrug[j0]][0] == "mg/hr") value[j0] = value[j0] * 1000;
                                else if (doseunit[samedrug[j0]][0] == "mg/min" || doseunit[samedrug[j0]][0] == "mg/kg/hr") value[j0] = value[j0] * 1000 / 60;
                                else if (doseunit[samedrug[j0]][0] == "mg/day" || doseunit[samedrug[j0]][0] == "mg/24h") value[j0] = value[j0] * 1000 / 24;

                                //为dosechange赋值
                                if (j0 == 0) dosechange[samedrug[j0]] = "I";
                                else if (value[j0] > value[j0 - 1]) {
                                    dosechange[samedrug[j0]] = "↑";
                                } else if (value[j0] < value[j0 - 1]) {
                                    dosechange[samedrug[j0]] = "↓";
                                } else if (value[j0] == value[j0 - 1]) {
                                    dosechange[samedrug[j0]] = "-";
                                } else dosechange[samedrug[j0]] = "x";
                            }


                        }


                        for (var r = 0; r < c; r++) {

                            if (starttime[r][0] == endtime[r][0]) {//时间点给药，end=start+1h

                                var stp = starttime[r][0]
                                var tp = new Date(stp)
                                // var edt = tp.setHours(tp.getHours() + 1)
                                var edt = new Date(tp.setHours(tp.getHours() + 1)).format("yyyy-MM-dd hh:mm:ss"); //解决mac和部分浏览器不兼容的问题

                                arrData[r] = {
                                    x: Date.UTC(chGMT(starttime[r][0]).slice(0, 4), chGMT(starttime[r][0]).slice(5, 7) - 1, chGMT(starttime[r][0]).slice(8, 10), chGMT(starttime[r][0]).slice(11, 13), chGMT(starttime[r][0]).slice(14, 16), chGMT(starttime[r][0]).slice(17, 19)),
                                    // x2: Date.UTC(chGMT(starttime[r][0]).slice(0, 4), chGMT(starttime[r][0]).slice(5, 7) - 1, chGMT(starttime[r][0]).slice(8, 10), chGMT(starttime[r][0]).slice(11, 13) + 1, chGMT(starttime[r][0]).slice(14, 16), chGMT(starttime[r][0]).slice(17, 19)),
                                    x2: Date.UTC(chGMT(edt).slice(0, 4), chGMT(edt).slice(5, 7) - 1, chGMT(edt).slice(8, 10), chGMT(edt).slice(11, 13), chGMT(edt).slice(14, 16), chGMT(edt).slice(17, 19)),
                                    y: in_array(drugcategory[r], drugresult),
                                    strength: strength[r][0],
                                    drug: drugcategory[r][0],
                                    dosevalue: dosevalue[r][0],
                                    doseunit: doseunit[r][0],
                                    dosechange: dosechange[r]
                                }
                            } else {

                                arrData[r] = {
                                    x: Date.UTC(chGMT(starttime[r][0]).slice(0, 4), chGMT(starttime[r][0]).slice(5, 7) - 1, chGMT(starttime[r][0]).slice(8, 10), chGMT(starttime[r][0]).slice(11, 13), chGMT(starttime[r][0]).slice(14, 16), chGMT(starttime[r][0]).slice(17, 19)),
                                    x2: Date.UTC(chGMT(endtime[r][0]).slice(0, 4), chGMT(endtime[r][0]).slice(5, 7) - 1, chGMT(endtime[r][0]).slice(8, 10), chGMT(endtime[r][0]).slice(11, 13), chGMT(endtime[r][0]).slice(14, 16), chGMT(endtime[r][0]).slice(17, 19)),
                                    y: in_array(drugcategory[r], drugresult),
                                    strength: strength[r][0],
                                    drug: drugcategory[r][0],
                                    dosevalue: dosevalue[r][0],
                                    doseunit: doseunit[r][0],
                                    dosechange: dosechange[r]

                                }

                            }
                        }


                        /*  本例子的目的是为了演示通过 Dom 事件、Highcharts 事件、Highcharts API 来讲一个页面中的多个图表进行联动的。
                            本例通过循环创建类似的图表并绑定鼠标的滑动事件来对多个图表进行演示联动效果。*/


                        $(function () {

                            /*
                             * 同步缩放效果，即当一个图表进行了缩放效果，其他图表也进行缩放
                             */
                            function syncExtremes(e) {
                                var thisChart = this.chart;
                                if (e.trigger !== 'syncExtremes') {
                                    Highcharts.each(Highcharts.charts, function (chart) {
                                        if (chart !== thisChart) {
                                            if (chart.xAxis[0].setExtremes) {
                                                chart.xAxis[0].setExtremes(e.min, e.max, undefined, false, {trigger: 'syncExtremes'});
                                            }
                                        }
                                    });
                                }
                            }


                            //用药情况
                            Highcharts.chart('timechart2', {
                                chart: {
                                    type: 'xrange',
                                    marginLeft: 150,
                                    zoomType: 'xy',
                                    panning: true,
                                    panKey: 'ctrl'


                                },
                                title: {
                                    text: 'MEDICATION-ICUSTAYID: ' + Term2
                                },
                                subtitle: {
                                    text: 'Drag to select the zoom area; Press ctrl to pan the chart left or right; Click on the legend to hide or resume display.'
                                },


                                xAxis: {
                                    type: 'datetime',
                                    events: {
                                        setExtremes: syncExtremes
                                    },
                                    title: {
                                        text: 'Medication Time'
                                    }


                                },

                                yAxis: [{
                                    title: {
                                        text: ''
                                    },
                                    categories: drugresult,//y轴的值(药品名称需要查询)
                                    reversed: true,//y轴值上下顺序反向
                                    tickInterval: 1
                                }],


                                tooltip: {//label样式

                                    headerFormat: '{point.x:%A,%b.%e,%Y,%H:%M:%S}-{point.x2:%A,%b.%e,%Y,%H:%M:%S}<br>',
                                    pointFormat: '<b>Drug:</b>{point.drug}<br><b>Strength:</b>{point.strength}<br><b>Dosage:</b>{point.dosevalue}{point.doseunit} ',
                                    positioner: function () {//固定标签显示位置
                                        return {x: this.chart.chartWidth - this.label.width - 1, y: 0};
                                    },
                                    // shadow: false,
                                    // shape: 'round',
                                    // borderWidth: 0,
                                    // backgroundColor: 'rgba(0,0,0,0.2)',

                                    crosshairs: [{            // 设置准星线样式
                                        width: 1,
                                        color: "#006cee",
                                        dashStyle: 'longdashdot'

                                    }, {
                                        width: 1,
                                        color: "#006cee",
                                        dashStyle: 'longdashdot'
                                    }]

                                },


                                legend: {//图例右侧显示
                                    layout: 'vertical',
                                    align: 'right',
                                    verticalAlign: 'middle'

                                },


                                series: [{
                                    name: 'Drugs',
                                    dashStyle: 'solid',
                                    //borderColor: 'gray',
                                    pointWidth: 5,
                                    data: arrData,
                                    dataLabels: {
                                        enabled: true,
                                        defer: false,
                                        inside: true,
                                        align: 'center',
                                        format: '{point.dosechange}'
                                    }

                                }]
                            });
                        });
                    }
                }
            })
        }



        function search_graph_surgeryvital(Term30, Term31) {
            //var Term =
            !{JSON.stringify(term)};
            $.ajax({
                url: "/search/graph_surgeryvital/list",
                type: "POST",
                data: {
                    term: Term30,
                    term1: Term31
                },

                success: function (data) {


                    var obj = {};
                    var obj1 = {};
                    var obj2 = {};
                    var obj3 = {};
                    var obj4 = {};
                    var obj5 = {};
                    var obj6 = {};
                    // var obj1 = {};
                    var arrData = [];


                    // var b = 0;


                    var tl = 0;//tl=sign_time.length

                    var sign_time = [];//体征记录时间，横轴
                    var sign_arr = [];
                    var sign_arr1 = [];
                    var sign_arr2 = [];
                    var sign_arr3 = [];
                    var sign_arr4 = [];
                    var sign_arr5 = [];
                    var sign_arr6 = [];
                    var sign_arr7 = [];

                    var k10 = 0;
                    var k20 = 0;
                    var k30 = 0;
                    var k40 = 0;
                    var k50 = 0;
                    var k60 = 0;
                    var k70 = 0;


                    if (data == '') {
                        alert("No or lack of relevant data!" + "\n" + "Click to close the message box.");
                        // window.close();

                    } else {
                        //alert("Success!");


                        //////////// SURGERY VITAL SIGN DATA ////////////


                        sign_arr[0] = data[0];//把重复的数据去掉,sign_arr包含全部charttime的所有数据
                        sign_time[0] = sign_arr[0].MONITOR_TIME;
                        var s = 1;//注意s是从1开始的，p也是从1开始的
                        for (var p = 1; p < data.length; p++) {//循环将所有记录的时间加入数组，确定横轴
                            if (data[p].MONITOR_TIME != data[p - 1].MONITOR_TIME) {
                                sign_arr[s] = data[p];
                                sign_time[s] = sign_arr[s].MONITOR_TIME;
                                s++;
                            }
                        }


                        for (var ks = 0; ks < s; ks++) {//signarr1-signarr6代表六种体征检测值
                            if (sign_arr[ks].HeartRate != null) {
                                sign_arr1[k10] = {//sign_arr的顺序另外计数
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].HeartRate)
                                }
                                k10++;
                            }
                            if (sign_arr[ks].Pulse != null) {
                                sign_arr2[k20] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].Pulse)
                                }
                                k20++;
                            }
                            if (sign_arr[ks].SystolicPressure != null) {
                                sign_arr3[k30] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].SystolicPressure)
                                }
                                k30++;
                            }
                            if (sign_arr[ks].DiastolicPressure != null) {
                                sign_arr4[k40] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].DiastolicPressure)
                                }
                                k40++;
                            }
                            if (sign_arr[ks].CentralVenousPressure != null) {
                                sign_arr5[k50] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].CentralVenousPressure)
                                }
                                k50++;
                            }
                            if (sign_arr[ks].RespiratoryRate != null) {
                                sign_arr6[k60] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].RespiratoryRate)
                                }
                                k60++;
                            }
                            if (sign_arr[ks].O2Saturation != null) {
                                sign_arr7[k70] = {
                                    x: Date.UTC(chGMT(sign_time[ks]).slice(0, 4), chGMT(sign_time[ks]).slice(5, 7) - 1, chGMT(sign_time[ks]).slice(8, 10), chGMT(sign_time[ks]).slice(11, 13), chGMT(sign_time[ks]).slice(14, 16), chGMT(sign_time[ks]).slice(17, 19)),
                                    y: Number(sign_arr[ks].O2Saturation)
                                }
                                k70++;
                            }


                        }


                        $(function () {
                            //同步缩放效果
                            function syncExtremes(e) {
                                var thisChart = this.chart;
                                if (e.trigger !== 'syncExtremes') {
                                    Highcharts.each(Highcharts.charts, function (chart) {
                                        if (chart !== thisChart) {
                                            if (chart.xAxis[0].setExtremes) {
                                                chart.xAxis[0].setExtremes(e.min, e.max, undefined, false, {trigger: 'syncExtremes'});
                                            }
                                        }
                                    });
                                }
                            }

                            //体征变化
                            Highcharts.chart('timechart3', {
                                chart: {
                                    type: 'spline',
                                    marginLeft: 150,
                                    zoomType: 'xy',
                                    panning: true,
                                    panKey: 'ctrl'

                                },
                                title: {
                                    text: 'SURGERY VITAL SIGNS-HADMID: ' + Term30 + ' OPERID: ' + Term31
                                },
                                subtitle: {
                                    text: 'Drag to select the zoom area; Press ctrl to pan the chart left or right; Click on the legend to hide or resume display.'
                                },
                                xAxis: {
                                    type: 'datetime',
                                    events: {
                                        setExtremes: syncExtremes //属性：该图zoom时其他图zoom (该chart不设，其他chart设置时，其他图zoom时改图也会zoom)
                                    },
                                    title: {
                                        text: 'Time In Hospital'
                                    }

                                },
                                yAxis: [{
                                    title: {
                                        text: 'Measurement, Absolute Value'
                                    },
                                    //reversed: true,//y轴值上下顺序反向
                                    tickInterval: 1,
                                    min: 0
                                }],

                                tooltip: {//label样式
                                    headerFormat: '<b>{series.name}:{point.y}</b><br>',
                                    pointFormat: '{point.x:%A,%b.%e,%Y,%H:%M:%S} ',
                                    positioner: function () {//固定标签显示位置
                                        return {x: this.chart.chartWidth - this.label.width - 1, y: 0};//x: this.chart.chartWidth - this.label.width 表示right aligned；y: -1 表示align to title
                                    },
                                    // shadow: false,
                                    // shape: 'round',
                                    // borderWidth: 0,
                                    // backgroundColor: 'rgba(0,0,0,0.2)',
                                    crosshairs: [{            // 设置准星线样式
                                        width: 1,
                                        color: "#006cee",
                                        dashStyle: 'longdashdot'

                                    }, {
                                        width: 1,
                                        color: "#006cee",
                                        dashStyle: 'longdashdot'
                                    }]
                                },
                                //     % a:星期的缩写, 比如'Mon'.
                                //     % A:星期的全写, 比如'Monday'.
                                //     % d:日期的写法, 比如：01到31.
                                //     % e:日期的写法, 1到31.
                                //     % b:月的缩写, 比如'Jan'.
                                //     % B:月的全写, 比如'January'.
                                //     % m:阿拉伯月的写法, 0112.
                                //     % y:年的缩写, 比如09代表2009.
                                //     % Y:年的全写, 比如2009.
                                //     % H:两位数的24小时写法, 比如00到23.
                                //     % I:两位数的12小时写法, 00到11.
                                //     % l(L字母的小写):12小时的写法, 1到11.
                                //     % M:分钟写法, 00到59.
                                //     % p:Upper case AM or PM.
                                //     % P:Lower case AM or PM.
                                //     % S:分钟写法, 00到59

                                legend: {//图例右侧显示
                                    layout: 'vertical',
                                    align: 'right',
                                    verticalAlign: 'middle'
                                },

                                plotOptions: {//line的图例标线
                                    series: {
                                        label: {
                                            connectorAllowed: false
                                        }
                                    },
                                    spline: {//标志点
                                        marker: {
                                            enabled: true
                                        }
                                    }
                                },

                                colors: ['#ae0000', '#ff85e5', '#036', '#ffc300', '#3ecc8c', '#6CF', '#696969'],
                                series: [{
                                    name: 'Heart Rate',
                                    data: sign_arr1
                                },
                                    {
                                        name: 'Pulse',
                                        data: sign_arr2
                                    },
                                    {
                                        name: 'Systolic Pressure',
                                        data: sign_arr3
                                    },
                                    {
                                        name: 'Diastolic Pressure',
                                        data: sign_arr4
                                    },
                                    {
                                        name: 'Central Venous Pressure',
                                        data: sign_arr5
                                    },
                                    {
                                        name: 'Respiratory Rate',
                                        data: sign_arr6
                                    },
                                    {
                                        name: 'O2 Saturation',
                                        data: sign_arr7
                                    }
                                ]
                            });

                        });
                    }
                }
            })
        }

        function search_graph_emrsymptom(Term4) {
        //var Term =
        !{JSON.stringify(term)};
            $.ajax({
                url: "/search/graph_emrsymptom/list",
                type: "POST",
                data: {term: Term4},

                success: function (data) {


                    var symcategory = [];
                    var symcategory_p = [];
                    var symcategory_n = [];
                    var symresult = [];
                    var obj = {};
                    var arrData_p = [];
                    var arrData_n = [];
                    var starttime = [];
                    var starttime_p = [];
                    var starttime_n = [];
                    var endtime = [];
                    var attribute = [];
                    var attribute_p = [];
                    var attribute_n = [];


                    if (data == '') {
                        alert("No or lack of relevant data!" + "\n" + "Click to close the message box.");
                        // window.close();

                    } else {
                        //alert("Success!");





                        ////////EMR SYMPTOM DATA/////////


                        var c = 0;

                        for (var q = 0; q < data.length; q++) {
                            symcategory[c] = [data[q].SYMPTOM_NAME_EN];
                            starttime[c] = [data[q].RECORD_TIME];
                            // endtime[c] = [data[q].RECORDTIME]; //都是点时间，直接设定endtime
                            attribute[c] = [data[q].SYMPTOM_ATTRIBUTE];
                            c++;
                        }

                        //删除重复元素
                        for (var i = 0; i < data.length; i++) {
                            if (!obj[symcategory[i]]) {
                                symresult.push(symcategory[i]);//symresult存储不重复症状名
                                obj[symcategory[i]] = true;
                            }
                        }
                        symresult.sort(); //将症状名称显示按照自上至下的字母顺序重排


                        //将症状分为两个series显示，所以先分成两个单独的数组group
                        var index_p = 0
                        var index_n = 0
                        for (var m = 0; m < c; m++) {
                            if (attribute[m][0].indexOf('+') == 0) {  //array中的element为+ (不存在则为-1)
                                symcategory_p[index_p] = symcategory[m];
                                starttime_p[index_p] = starttime[m];
                                attribute_p[index_p] = attribute[m];
                                index_p++;
                            } else {
                                symcategory_n[index_n] = symcategory[m];
                                starttime_n[index_n] = starttime[m];
                                attribute_n[index_n] = attribute[m];
                                index_n++;
                            }

                        }


                        for (var r = 0; r < index_p; r++) {
                            // var stp = starttime_p[r][0]
                            // var tp = new Date(stp)
                            // var endtime_p = tp.setHours(tp.getHours()+1)
                            for (var u = symcategory_p.length - 1; u >= 0; u--) {
                                if (symcategory_p[r][0] == symcategory_p[u][0]) break;
                            }


                            arrData_p[r] = {
                                x: Date.UTC(chGMT(starttime_p[r][0]).slice(0, 4), chGMT(starttime_p[r][0]).slice(5, 7) - 1, chGMT(starttime_p[r][0]).slice(8, 10), chGMT(starttime_p[r][0]).slice(11, 13), chGMT(starttime_p[r][0]).slice(14, 16), chGMT(starttime_p[r][0]).slice(17, 19)),
                                //线段表示
                                x2: Date.UTC(chGMT(starttime_p[u][0]).slice(0, 4), chGMT(starttime_p[u][0]).slice(5, 7) - 1, chGMT(starttime_p[u][0]).slice(8, 10), chGMT(starttime_p[u][0]).slice(11, 13), chGMT(starttime_p[u][0]).slice(14, 16), chGMT(starttime_p[u][0]).slice(17, 19)),
                                //点表示
                                // x2: Date.UTC(chGMT(endtime_p).slice(0, 4), chGMT(endtime_p).slice(5, 7) - 1, chGMT(endtime_p).slice(8, 10), chGMT(endtime_p).slice(11, 13), chGMT(endtime_p).slice(14, 16), chGMT(endtime_p).slice(17, 19)),
                                y: in_array(symcategory_p[r], symresult),
                                sym: symcategory_p[r][0],
                                attribute: attribute_p[r],
                                color: '#ffc1c1'
                            }
                        }
                        for (var r = 0; r < index_n; r++) {
                            // var stn = starttime_n[r][0]
                            // var tn = new Date(stn)
                            // var endtime_n = tn.setHours(tn.getHours() + 1)
                            for (var v = symcategory_n.length - 1; v >= 0; v--) {
                                if (symcategory_n[r][0] == symcategory_n[v][0]) break;
                            }
                            arrData_n[r] = {
                                x: Date.UTC(chGMT(starttime_n[r][0]).slice(0, 4), chGMT(starttime_n[r][0]).slice(5, 7) - 1, chGMT(starttime_n[r][0]).slice(8, 10), chGMT(starttime_n[r][0]).slice(11, 13), chGMT(starttime_n[r][0]).slice(14, 16), chGMT(starttime_n[r][0]).slice(17, 19)),
                                //线段表示
                                x2: Date.UTC(chGMT(starttime_n[v][0]).slice(0, 4), chGMT(starttime_n[v][0]).slice(5, 7) - 1, chGMT(starttime_n[v][0]).slice(8, 10), chGMT(starttime_n[v][0]).slice(11, 13), chGMT(starttime_n[v][0]).slice(14, 16), chGMT(starttime_n[v][0]).slice(17, 19)),
                                //点表示
                                // x2: Date.UTC(chGMT(endtime_n).slice(0, 4), chGMT(endtime_n).slice(5, 7) - 1, chGMT(endtime_n).slice(8, 10), chGMT(endtime_n).slice(11, 13), chGMT(endtime_n).slice(14, 16), chGMT(endtime_n).slice(17, 19)),
                                y: in_array(symcategory_n[r], symresult),
                                sym: symcategory_n[r][0],
                                attribute: attribute_n[r],
                                color: '#b1a8ad'

                            }
                        }


                        $(function () {
                            function syncExtremes(e) {
                                var thisChart = this.chart;
                                if (e.trigger !== 'syncExtremes') {
                                    Highcharts.each(Highcharts.charts, function (chart) {
                                        if (chart !== thisChart) {
                                            if (chart.xAxis[0].setExtremes) {
                                                chart.xAxis[0].setExtremes(e.min, e.max, undefined, false, {trigger: 'syncExtremes'});
                                            }
                                        }
                                    });
                                }
                            }


                            //症状显示
                            Highcharts.chart('timechart4', {

                                chart: {
                                    type: 'xrange',
                                    marginLeft: 150,
                                    zoomType: 'xy',
                                    panning: true,
                                    panKey: 'ctrl'


                                },
                                title: {
                                    text: 'EMR SYMPTOM-HADMID: ' + Term4 + ' EMRID: ' + data[0].EMR_ID
                                },
                                subtitle: {
                                    text: 'Drag to select the zoom area; Press ctrl to pan the chart left or right; Click on the legend to hide or resume display.'
                                },


                                xAxis: {
                                    type: 'datetime',
                                    events: {
                                        setExtremes: syncExtremes
                                    },
                                    title: {
                                        text: 'Time In Hospital'
                                    }


                                },

                                yAxis: [{
                                    title: {
                                        text: ''
                                    },
                                    categories: symresult,//y轴的值
                                    reversed: true,//y轴值上下顺序反向
                                    tickInterval: 1
                                }],


                                tooltip: {//label样式

                                    headerFormat: '<b>Record Time:</b>{point.x:%A,%b.%e,%Y,%H:%M:%S}<br>',
                                    pointFormat: '<b>Symptom Name:</b>{point.sym}<br><b>Attribute:</b>{point.attribute}<br>',
                                    positioner: function () {//固定标签显示位置
                                        return {x: this.chart.chartWidth - this.label.width - 1, y: 0};
                                    },
                                    // shadow: false,
                                    // shape: 'round',
                                    // borderWidth: 0,
                                    // backgroundColor: 'rgba(0,0,0,0.2)',

                                    crosshairs: [{            // 设置准星线样式
                                        width: 1,
                                        color: "#006cee",
                                        dashStyle: 'longdashdot'

                                    }, {
                                        width: 1,
                                        color: "#006cee",
                                        dashStyle: 'longdashdot'
                                    }]

                                },


                                legend: {//图例右侧显示
                                    layout: 'vertical',
                                    align: 'right',
                                    verticalAlign: 'middle',

                                },


                                series: [{
                                    name: 'Symptoms+',
                                    dashStyle: 'solid',
                                    pointWidth: 2,
                                    data: arrData_p,
                                    color:'#ffc1c1',
                                    dataLabels: {
                                        enabled: true,
                                        defer: false,
                                        inside: true,
                                        align: 'center'
                                    },


                                },
                                    {
                                        name: 'Symptoms-',
                                        dashStyle: 'solid',
                                        pointWidth: 2,
                                        data: arrData_n,
                                        color: '#b1a8ad',
                                        dataLabels: {
                                            enabled: true,
                                            defer: false,
                                            inside: true,
                                            align: 'center'
                                        }

                                    }]

                            });
                        });
                    }
                }
            })
        }


























        Date.prototype.format = function (format) {
            var o = {
                "M+": this.getMonth() + 1, //month
                "d+": this.getDate(), //day
                "h+": this.getHours(), //hour
                "m+": this.getMinutes(), //minute
                "s+": this.getSeconds(), //second
                "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
                "S": this.getMilliseconds() //millisecond
            }
            if (/(y+)/.test(format))
                format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            for (var k in o)
                if (new RegExp("(" + k + ")").test(format))
                    format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
            return format;
        }

        function chGMT(gmtDate) {
            // var mydate = new Date(gmtDate);
            // mydate.setHours(mydate.getHours());
            // return mydate.format("yyyy-MM-dd hh:mm:ss");
            return gmtDate;
        }

        function in_array(searchString, array) {
            for (var i = 0; i < array.length; i++) {
                if (searchString == array[i][0]) return i;
            }
            return -1;
        }

        function isObjEqual(o1, o2) {
            var props1 = Object.getOwnPropertyNames(o1);
            var props2 = Object.getOwnPropertyNames(o2);
            if (props1.length != props2.length) {
                return false;
            }
            for (var i = 0, max = props1.length; i < max; i++) {
                var propName = props1[i];
                if (o1[propName] !== o2[propName]) {
                    return false;
                }
            }
            return true;
        }

        // 对于xrange右侧的图例，使其可以在series中设置color显示颜色（默认全为灰色），应用：emr symptoms
        (function (H) {
            H.Legend.prototype.getAllItems = function () {
                var allItems = [];
                len = this.chart.series.length;
                H.each(this.chart.series, function (series) {
                    if (series == undefined) ; //在同一个div多次加载图片会造成覆盖（renderTo由div的id变为undefined），无法显示，将此排除并进行each循环
                    else {
                        var seriesOptions = series && series.options;
                        if (series.name === 'Symptoms+' || series.name === 'Symptoms-') {
                            series.color = series.userOptions.color
                        }
                        if (series && H.pick(
                            seriesOptions.showInLegend,
                            !H.defined(seriesOptions.linkedTo) ? undefined : false, true
                        )) {
                            allItems = allItems.concat(
                                series.legendItems ||
                                (
                                    seriesOptions.legendType === 'point' ?
                                        series.data :
                                        series
                                )
                            );
                        }
                    }

                });

                H.fireEvent(this, 'afterGetAllItems', {allItems: allItems});
                return allItems;
            }
        })(Highcharts)















        window.onload = function () {


            search_id();

        }



